<?php require ('setcookie.html'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="de">
<head>
    <title>Lingomoto - Einstellungen - Sprachen lernen</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Lingomoto - Einstellungen - Sprachen lernen" />
    <meta name="language" content="de" />
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>

<body id="account">
<?php
$_SESSION['logini'] = isset($_SESSION['logini']) ? $_SESSION['logini'] : false;
// read configuration
require ('konfiguration.html');
// read user-data
require ('nutzer.html');
// read header
$link = "einstellungen.html";
$langen = 'settings.html';
$langes = 'ajustes.html';
$langru = 'settings.html';
require ('kopf.html');
// <!-- horizontal column -->
echo '<div>';
require ('horizontal.html');
echo '</div>';
// <!-- Left Column -->
echo '<div id="left_col">';
require ('vertikal.html');
echo '</div>';

// <!-- Content -->
echo '<div id="content">';
echo '<div id="block5">';

// request for login
if ($_SESSION['logini']== false) {
    require_once ('loginformular.html'); 
}

// if new password, request for change of password
elseif ( $newpass == 1 )
{
$passwo = isset($_REQUEST['passwo']) ? $_REQUEST['passwo'] : '1';
$passwo1 = isset($_REQUEST['passwo1']) ? $_REQUEST['passwo1'] : '1';
$passwo2 = isset($_REQUEST['passwo2']) ? $_REQUEST['passwo2'] : '1';
$ok='';
require_once ('neues-passwort.html');
}

else {
// initialize variables
$change_new = isset($_REQUEST['change_new']) ? $_REQUEST['change_new'] : '';
$change_old = isset($_REQUEST['change_old']) ? $_REQUEST['change_old'] : '';

if ( $change_new <> '' ) { require_once ('newlangeinstellungen.html'); }
if ( $change_old <> '' ) { require_once ('oldlangeinstellungen.html'); }

show_form();
}

// ----------------------- Functions --------------------------------------------------------------------------------------------

function show_form() {

    $customerid = $_SESSION['customerid']; 
    $langpair = isset($_REQUEST['langpair']) ? $_REQUEST['langpair'] : '';

    $sql = "SELECT * FROM settings where customerid = ". $customerid;
    $sql3 = "SELECT distinct learn FROM langpairs_german order by learn";
    $sql4 = "SELECT distinct can FROM langpairs_german order by can";
    
    // DB Query
    $db_res = mysql_query( $sql );
    if ( ! $db_res ) { die('Error query1: ' . mysql_error()); }
    $db_sel3 = mysql_query( $sql3 );
    if ( ! $db_sel3 ) { die('Error query2: ' . mysql_error()); }
    $db_sel4 = mysql_query( $sql4 );
    if ( ! $db_sel4 ) { die('Error query3: ' . mysql_error()); }

    echo '<form action="einstellungen.html" method="post" >';
    echo '<h2>Einstellungen</h2>';
        echo '<br />';
    echo '<div class="content_frame">';
    echo 'Spracheinstellungen:<br /><br />';

    // Show custoomer data
    while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
    $langpair = $row['langpair'];
    $new = $row['learnde'];
    if ( $new == '' ) { $new = '-'; }
    $old = $row['cande'];
    if ( $old == '' ) { $old = '-'; }
        echo '<div class="left2">Ich m&ouml;chte lernen:</div>';
        echo '<div class="marginbottom"><b>'. $new . '</b>&nbsp;</div>';
        // change new language
        echo '<div class="marginleft4">';
        echo '<select class="fixwidth" name="change_new" onchange=submit()>';
        echo '<option value="" >&auml;ndern?&nbsp;</option>';
        while ($row = mysql_fetch_array( $db_sel3, MYSQL_ASSOC)) {
        if ( $row['learn'] <> $new )
        { echo '<option value="'. $row['learn'] . '" >'. $row['learn'] . '</option>'; }
        }
        echo '</select>';
        echo '</div>';
  
        echo '<br />';
        echo '<br />';

        echo '<div class="left2">Ausgangssprache:</div>';
        echo '<div class="marginbottom"><b>'. $old . '</b>&nbsp;</div>';
        // change old language
        echo '<div class="marginleft4">';
        echo '<select class="fixwidth" name="change_old" onchange=submit()>';
        echo '<option value="" >&auml;ndern?&nbsp;</option>';
        while ($row = mysql_fetch_array( $db_sel4, MYSQL_ASSOC)) {
        if ( $row['can'] <> $old )
        { echo '<option value="'. $row['can'] . '" >'. $row['can'] . '</option>'; }
        }
        echo '</select>';
        echo '</div>';
    }
    
    // if no langpairs are selected
    $num_rows = mysql_num_rows($db_res); 
    if ( $num_rows == 0 )   { echo "<div class='message'>Keine Sprache ausgew&auml;hlt!</div>"; }
    echo '<br />';

    echo '</div>';

    echo '<br />';

    echo '<div class="content_frame">';
    echo 'Pers&ouml;nliche Einstellungen:<br /><br />';
    echo '<span class="link"><a href="passwort-aendern.html">Passwort &auml;ndern?</a></span>';
    echo '</div>';


    echo '</form>';
}   

      
echo '</div>';
echo '</div>';
echo '<div id="adverts">';
echo '<div id="adbox"></div>';
echo '</div>';
    
require ('fuss.html');
?>

</body>
</html>